const fs=require('fs');
const path=require('path');
const stdin=process.stdin;
const log=console.log;

var tips=['请输入要创建的文件夹','请输入要创建的文件','请输入要删除的文件'];
log(tips[0]);
var index=0;
var dirname='';
stdin.on('data',(chunk)=>{
    if(index==3){
        process.exit();
    }
    chunk=chunk.toString('utf-8');
    if(index==0){
        dirname=chunk.slice(6,-2);
        var dirPath=path.join(__dirname,'/'+dirname);
        fs.mkdir(dirPath,(err)=>{
            if(err){
                log(err);
            }
            else{
                log(`${dirname} was created`);
            }
        })
    }else if(index==1){
        filename=chunk.slice(6,-2);
        var filePath=path.join(__dirname,`/${dirname}/${filename}`);
        var writable=fs.createWriteStream(filePath);
        writable.write('hello node');
        writable.end();
    }else{
        delfilename=chunk.slice(0,-2);
        var delfilePath=path.join(__dirname,`/${dirname}/${delfilename}`);
        var fileObj=fs.statSync(delfilePath);
        fs.unlinkSync(delfilePath,(err)=>{
            if(err){
                log(err);
            }else{
                log(`file was deleted!!!`);
            }
        })
    }
    index++;
    log(tips[index]);
})